package me.hbz.myblog.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import me.hbz.myblog.domain.Nav;
import me.hbz.myblog.doman.utils.DBUtils;

public class NavDAO {
	public List<Nav> findAll() throws SQLException{
		Connection conn = DBUtils.getConnection();
			
			String sql = "select * from nav";
			
			PreparedStatement st = conn.prepareStatement(sql);
			
			ResultSet rs= st.executeQuery();
			
			List<Nav> navList = new ArrayList<>();
			while(rs.next()) {
				Nav nav = new Nav();
				nav.setId(rs.getInt("id"));
				nav.setTitle(rs.getString("title"));
				nav.setInside(rs.getBoolean("inside"));
				nav.setUrl(rs.getString("url"));
				
				navList.add(nav);
			}
			DBUtils.closeResource(conn, st, rs);
			return navList;
				
	}
}
